import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'dayjs/locale/zh-cn'

import createRoutes from './createRoutes'

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

app.use(createPinia())

app.use(ElementPlus, {
  locale: zhCn,
})

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}


createRoutes(router, function () {

  app.use(router)
  app.mount('#app')
})

// v - a=""

// h1  v-permission="'666'"
// p

// v-bind:src ="1.jpg"
// v-bind:href="1.html"

import { useUserStore } from './stores/user'
app.directive('permission', {

  mounted(el, binding) {

    const { userInfo } = useUserStore()
    // el  h1
    // el.remove()
    // console.log(el)
    // console.log(binding.value)
    // console.log(userInfo.permission)

    if (!userInfo.permission.includes(binding.value)) {
      // el.remove()
      el.addEventListener('click', (e: Event) => {
        alert('没权限')
        e.stopPropagation()
      }, true)
    }

  }

})
